package javabase.schoolwork.day6_10;

/**
 * @author fance
 * @date 2018/6/10 13:44
 */
public class Info {
    private String name = "fance";
    private String content = "boy";
    private volatile boolean flag = false;
    public synchronized void set(String name,String content) throws InterruptedException {
        if (!flag) {
            super.wait();
        }
        this.setName(name);
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        this.setContent(content);
        flag = false;
        super.notify();
    }
    public synchronized void get() throws InterruptedException {
        if (flag) {
            super.wait();
        }
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(this.getName() +
                "--> " + this.getContent());
        flag = true;
        super.notify();

    }/* public synchronized void set(String name,String content) {
        this.setName(name);
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        this.setContent(content);
    }
    public synchronized void get() {
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(this.getName() +
                "--> " + this.getContent());

    }*/
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
}
